import { defineStore } from 'pinia';
import axios from '../api/request.ts';

export const useActivityReviewStore = defineStore('activityReview', {
    state: () => ({
        reviews: [] as any[],
    }),
    actions: {
        async fetchReviews() {
            try {
                const response = await axios.get('/activity-reviews');
                this.reviews = response.data;
                return this.reviews;
            } catch (error) {
                console.error('Error fetching reviews:', error);
            }
        },
        async addReview(review: { activityId: number, reviewContent: string, userId: number }) {
            try {

                const response = await axios.post('/activity-reviews', review);
                this.reviews.push(response.data);
            } catch (error) {
                console.error('Error adding review:', error);
            }
        },
        async deleteReview(reviewId: number) {
            try {
                await axios.delete(`/activity-reviews/${reviewId}`);
                this.reviews = this.reviews.filter(review => review.id !== reviewId);
            } catch (error) {
                console.error('Error deleting review:', error);
            }
        },
    },
});
